class Solution(object):
    def tilingRectangle(self, n, m):
        st = [0 for _ in range(n)]
        self.ans = m * n
        def dfs(val):
            if val < self.ans:
                temp = [[num, index] for index, num in enumerate(st)]
                min_num, min_index = min(temp)
                if min_num == m:
                    self.ans = val
                else:
                    now_max = 0
                    for index in range(min_index, n):
                        if st[index] == min_num:
                            now_max += 1
                        else:
                            break
                    now_max = min(m - min_num, now_max)
                    for k in range(now_max, 0, -1):
                        for j in range(min_index, min_index + k):
                            st[j] += k
                        dfs(val + 1)
                        for j in range(min_index, min_index + k):
                            st[j] -= k
        dfs(0)
        return self.ans 

data = Solution()
n = 11
m = 13
print(data.tilingRectangle(n, m))


                


                
